package com.gjy.leetcode;

import org.junit.jupiter.api.Test;

/**
 * 2383. 赢得比赛需要的最少训练时长
 *
 * @author 宫静雨
 * @version 1.0
 * @since 2023-03-13 09:12:27
 */
public class A2383 {

    public int minNumberOfHours(int initialEnergy, int initialExperience, int[] energy, int[] experience) {
        int sum = 0;
        for (int e : energy) {
            sum += e;
        }
        int trainingHours = initialEnergy > sum ? 0 : sum + 1 - initialEnergy;
        for (int e : experience) {
            if (initialExperience <= e) {
                trainingHours += 1 + (e - initialExperience);
                initialExperience = 2 * e + 1;
            } else {
                initialExperience += e;
            }
        }
        return trainingHours;
    }

    @Test
    public void test1() {

    }
}
